//
//  HCMineAppView.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/21.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCMineAppView.h"

#import "HCMineAppTableViewCell.h"

#import "HCMineAppointmentModel.h"


@interface HCMineAppView () <UITableViewDelegate,UITableViewDataSource> {
    UITableView *tableView_;
    HCMineAppointmentModel *model_;
}

@end

@implementation HCMineAppView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubView:frame];
    }
    return self;
}

-(void)initializeSubView:(CGRect)frame {
    tableView_ = [[UITableView alloc] initWithFrame:frame];
    tableView_.delegate= self;
    tableView_.dataSource = self;
    tableView_.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView_.rowHeight = YBKAdaptiveH(118);
    tableView_.backgroundColor = YBKRGBCOLOR(242, 242, 242, 1);
    [self addSubview:tableView_];
    
    
    
    [tableView_ registerNib:[UINib nibWithNibName:@"HCMineAppTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"mineapptable"];
    
    tableView_.mj_header =  [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        NSLog(@"开始刷新");
        [self.delegate mineAppRefresh:tableView_];
        
    }];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (model_) {
        return model_.appoint.count;
    }else{
        return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HCMineAppTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mineapptable" forIndexPath:indexPath];
    
    if (model_) {
        cell.model = model_.appoint[indexPath.row];
    }
    
    return cell;
}

-(void)setModel:(id)model {
    _model = model;
    
    model_ = (HCMineAppointmentModel *)_model;
    
    [tableView_ reloadData];
    
}


/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
